package com.ljy.my_study.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

/** 
* @author James
* @date 2018年6月1日 
*/
public class SocketClient {
	public static void main(String[] args) {
		Socket clientSocket=null;
		try {
			clientSocket=new Socket("127.0.0.1",8888);
			PrintWriter output=new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream()),true);
			BufferedReader input=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
			
			output.println("hello 服务端！");

			while(true) {
				String line=input.readLine();
				if(line==null) {
					break;
				}
				System.out.println("客服端收到信息："+line);
			}
			input.close();
			output.close();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			if(clientSocket!=null) {
				try {
					clientSocket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
